import { ref } from "vue";
import { fetchChartComponent } from "@/packages/index";
import APP from '@/main.js'
export const useComInstall = (localStorageInfo) => {
  const show = ref(false);

  // 注册组件(一开始无法获取APP)
  const intervalTiming = setInterval(() => {
    if (APP.component) {
      clearInterval(intervalTiming);

      const intComponent = (target) => {
        if (!APP.component(target.chartConfig.chartKey)) {
          APP.component(
            target.chartConfig.chartKey,
            fetchChartComponent(target.chartConfig)
          );
        }
      };

      localStorageInfo.renderComponentList.forEach(async (e) => {
        if (e.isGroup) {
          e.groupList.forEach((groupItem) => {
            intComponent(groupItem);
          });
        } else {
          intComponent(e);
        }
      });
      show.value = true;
    }
  }, 200);

  return {
    show,
  };
};
